package com.yanqu.road.server.gameplayer.module.vehicle;

import com.yanqu.road.entity.player.UserVehicleBone;
import com.yanqu.road.pb.vehicle.VehicleProto;
import com.yanqu.road.utils.string.StringUtils;

import java.util.List;
import java.util.Map;

public class VehicleBonePb {
    public static VehicleProto.VehicleBoneTemp.Builder parseStoneTempBuilder(UserVehicleBone boneData) {
        VehicleProto.VehicleBoneTemp.Builder builder = VehicleProto.VehicleBoneTemp.newBuilder();
        builder.setId(boneData.getBoneId());
        builder.setConfigId(boneData.getConfigId());
        for (Map.Entry<Integer, Integer> entry : boneData.getSkillMap().entrySet()) {
            int skillId = entry.getKey();
            int lv = entry.getValue();
            builder.addSkill(VehicleProto.VehicleOtherSkillTempMsg.newBuilder().setSkillId(skillId).setSkillLv(lv).setType(0));
        }
        if (!StringUtils.isNullOrEmpty(boneData.getVehicleId())){
            VehicleProto.VehicleBoneEquipMsg.Builder equipBuilder = VehicleProto.VehicleBoneEquipMsg.newBuilder();
            equipBuilder.setVehicleId(boneData.getVehicleId());
            equipBuilder.setEquipTime(boneData.getEquipTime());
            equipBuilder.setPos(boneData.getEquipPos());
            builder.setEquip(equipBuilder);
        }

        return builder;
    }

    public static VehicleProto.VehicleBoneSyncMsg.Builder parseStoneSyncBuilder(List<UserVehicleBone> dataList) {
        VehicleProto.VehicleBoneSyncMsg.Builder builder = VehicleProto.VehicleBoneSyncMsg.newBuilder();
        for (UserVehicleBone userVehicleBone : dataList) {
            if (userVehicleBone.getIsDelete()) {
                continue;
            }
            builder.addBone(parseStoneTempBuilder(userVehicleBone));
        }
        return builder;
    }
}
